Adding middlewares on the server
Catalyst offers a flexible approach to defining server-side code, granting you greater control and customization over server operations.
Steps to add a middleware on the server
- To modify the server behavior, create a file named
server.js
within the server directory of your app. - Define a function named
addMiddlewares
, which receives the app server instance as a parameter. Catalyst provides this instance when executing the function on the server. - Use the
app
parameter to configure middleware for your application.
server/server.js
export function addMiddlewares(app) {
// server code
}
This express server instance enables you to integrate middleware, logging, and handle incoming requests effectively.
Adding middlewares
Integrating middleware follows a familiar process, like traditional Node.js servers.
server/server.js
export function addMiddlewares(app) {
app.use(path, middleware)
app.use(path, middleware)
app.use(path, middleware)
}
Example
server/server.js
import logger from logger
export function addMiddlewares(app) {
app.use("*", logger)
}